<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\common\model\ding;

use cores\BaseModel;

/**
 * 用户余额变动明细模型
 * Class BalanceLog
 * @package app\common\model\user
 */
class Coupon extends BaseModel
{
    // 定义表名
    protected $name = 'ding_coupon';

    // 定义主键
    protected $pk = 'coupon_id';

    protected $updateTime = false;
/**
 * 追加字段
 * @var array
 */
    protected $append = ['start_date', 'end_date'];

    public function getStartDateAttr($value, $data)
    {

        return Date('Y-m-d');
    }

    public function getEndDateAttr($value, $data)
    {

        return Date('Y-m-d', $data['expire_day'] * 86400 + time());
    }
    public static function detail($where, array $with = [])
    {
        return static::get($where, $with);
    }
    
    /**
     * 累计优惠券已领取的数量
     * @param int $couponId
     * @return mixed
     */
    public static function setIncReceiveNum(int $couponId)
    {
        return (new static)->setInc($couponId, 'receive_num', 1);
    }
}
